const path = require('path')
const webpack = require('webpack')

module.exports = {
  devServer: {
    open: true,
  },
  chainWebpack: config => {
     // 这里是对环境的配置，不同环境对应不同的VUE_APP_BASE_URL，以便axios的请求地址不同
     config.plugin('define').tap(args => {
      args[0]['process.env'].VUE_APP_BASE_URL = JSON.stringify(process.env.VUE_APP_BASE_URL)
      return args
    }),
    // 分割代码
    config.optimization.splitChunks({
      chunks: 'all'
    }),
    // 设置别名
    config.resolve.alias
      .set('@', path.resolve(__dirname, 'src'))
      .set('@api', path.resolve(__dirname, 'src/api'))
      .set('@comp', path.resolve(__dirname, 'src/components'))
      .set('@mix', path.resolve(__dirname, 'src/mixins'))
      .set('@view', path.resolve(__dirname, 'src/views'))
      .set('@assets', path.resolve(__dirname, 'src/assets'))
      .set('@utils', path.resolve(__dirname, 'src/utils'))
    // 优化moment 去掉国际化内容
    // config.plugin('ignore')
    // 忽略/moment/locale下的所有文件
    // .use(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)) 
    config.externals({
      'echarts': 'echarts',
      'WxLogin': 'WxLogin'
    })
  },
  configureWebpack: config => {
    config.entry.app = ["babel-polyfill", "./src/main.js"];
  },
}